//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
public class Main {
    public static void main(String[] args) {
        //斐波那契数递归
        //System.out.println(Fib(1));
        //顺序打印
       // function(1456);

//        int n = 5;
//        int ret = factor(n);
//        System.out.println("ret = "+ ret);
        //fun(120);
        //fun2(139);
       // System.out.println(fun3(3));

        System.out.println(Fbi2(3));
    }
    public static int Fib(int n){
        int f1 = 1;
        int f2 = 1;
        int f3 = 1;
        for (int i = 3; i <= n ; i++) {
            f3 = f1 + f2;
            f1 = f2;
            f2 = f3;
        }
        return f3;
    }
    //递归
    public static void function(int a){
        if (a == 1){
            System.out.print(a+" ");
            return;
        }
        function(a - 1);
        System.out.print(a+" ");
    }

    public static int factor(int n) {
        System.out.println("函数开始，n = "+n);
        if ( n == 1){
            System.out.println("函数结束，n =1 ret = 1 ");
            return 1;
        }
        int ret = n * factor(n - 1);
        System.out.println("函数结束，n = "+n +" ret =  "+ret);
        return ret;
    }

    public static void fun(int n) {
        if ( n >= 10){
            fun(n / 10);
        }
        System.out.println(n % 10);
    }
    public static void fun2(int n){
        if (n < 10){
            System.out.println(n);
            return;
        }
        fun2(n/10);
        System.out.println(n%10);
    }
    public static int fun3(int n){
        if (n == 1){
            return 1;
        }
        return n + fun3(n-1);
    }
    public static int Fbi2(int n){
        if (n == 1 || n ==2){
            return 1;
        }
        return Fbi2(n-1) + Fbi2(n-2);
    }
}